package com.dayu.recovery.service.impl;

import java.util.List;
import com.dayu.common.utils.DateUtils;
import com.dayu.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dayu.recovery.mapper.RecoveryArrangeMapper;
import com.dayu.recovery.domain.RecoveryArrange;
import com.dayu.recovery.service.IRecoveryArrangeService;

/**
 * 打理日志Service业务层处理
 * 
 * @author HK
 * @date 2021-04-28
 */
@Service
public class RecoveryArrangeServiceImpl implements IRecoveryArrangeService 
{
    @Autowired
    private RecoveryArrangeMapper recoveryArrangeMapper;

    /**
     * 查询打理日志
     * 
     * @param arrangeId 打理日志ID
     * @return 打理日志
     */
    @Override
    public RecoveryArrange selectRecoveryArrangeById(Long arrangeId)
    {
        return recoveryArrangeMapper.selectRecoveryArrangeById(arrangeId);
    }

    @Override
    public List<RecoveryArrange> selectArrangeListByExport(RecoveryArrange recoveryArrange) {
        return recoveryArrangeMapper.selectArrangeListByExport(recoveryArrange);
    }

    /**
     * 查询打理日志列表
     * 
     * @param recoveryArrange 打理日志
     * @return 打理日志
     */
    @Override
    public List<RecoveryArrange> selectRecoveryArrangeList(RecoveryArrange recoveryArrange)
    {
        return recoveryArrangeMapper.selectRecoveryArrangeList(recoveryArrange);
    }

    /**
     * 新增打理日志
     * 
     * @param recoveryArrange 打理日志
     * @return 结果
     */
    @Override
    public int insertRecoveryArrange(RecoveryArrange recoveryArrange)
    {
        List<RecoveryArrange> arranges = selectRecoveryArrangeList(recoveryArrange);
        if(arranges != null && arranges.size() > 0) {
            arranges.get(0).setStatus(2);   //作废
            updateRecoveryArrange(arranges.get(0));
        }
        recoveryArrange.setCreateBy(SecurityUtils.getLoginUser().getUser().getNickName());
        recoveryArrange.setCreateTime(DateUtils.getNowDate());
        return recoveryArrangeMapper.insertRecoveryArrange(recoveryArrange);
    }

    /**
     * 修改打理日志
     * 
     * @param recoveryArrange 打理日志
     * @return 结果
     */
    @Override
    public int updateRecoveryArrange(RecoveryArrange recoveryArrange)
    {
        recoveryArrange.setUpdateBy(SecurityUtils.getLoginUser().getUser().getNickName());
        recoveryArrange.setUpdateTime(DateUtils.getNowDate());
        return recoveryArrangeMapper.updateRecoveryArrange(recoveryArrange);
    }

    /**
     * 批量删除打理日志
     * 
     * @param arrangeIds 需要删除的打理日志ID
     * @return 结果
     */
    @Override
    public int deleteRecoveryArrangeByIds(Long[] arrangeIds)
    {
        return recoveryArrangeMapper.deleteRecoveryArrangeByIds(arrangeIds);
    }

    /**
     * 删除打理日志信息
     * 
     * @param arrangeId 打理日志ID
     * @return 结果
     */
    @Override
    public int deleteRecoveryArrangeById(Long arrangeId)
    {
        return recoveryArrangeMapper.deleteRecoveryArrangeById(arrangeId);
    }
}
